<template>
	<view class="box">
		<view class="top">
			<u-navbar :is-back="true" title="积分商城" :border-bottom="false" :title-bold="true"></u-navbar>
		</view>
		<!-- 商品数据 -->
		<view class="wrap" v-if="flowList.length>0">
			<u-waterfall v-model="flowList" ref="uWaterfall1">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index" @click="goDetail(item.id)">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.images_format[0]"
							:index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price flc">
							<view class="point">
								{{item.point}}积分
							</view>
						</view>

					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index"
						@click="goDetail(item.id)">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.images_format[0]"
							:index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price flc">
							<view class="point">
								{{item.point}}积分
							</view>
						</view>

					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus"></u-loadmore>
		</view>
		<view class="noData" style="width: 410rpx; height: 240rpx; margin: 60rpx auto;" v-else>
			<image src="../../static/img/empty.png" mode="widthFix" style="width: 410rpx; height: 240rpx;"></image>
		</view>
	</view>
</template>
<script>
	import {
		getPointGoods
	} from '@/api/index.js'
	import baseUrl from '@/config/config.js'
	import {
		closeload,
		tiao,
		toastload
	} from '@/utils/common.js'
	export default {
		data() {
			return {
				scroll: false,
				tabList: [{
					name: "全部"
				}],
				current: 0,
				// 显示加载更多
				loadStatus: 'loadmore',
				flowList: [],
				// 瀑布流数据
				goodList: [],
				page: 1,
				type: "",
				showTab: false
				// 自定义背景颜色

			}
		},
		onLoad() {
			this.getAllGoods()
			this.init()
		},
		// 上拉加载
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			if (this.loadStatus == 'loadmore') {
				this.getAllGoods()
			}
		},
		methods: {
			change(v) {
				this.current = v
				this.flowList = []
				this.goodList = []
				this.loadStatus = 'loading'
				this.page = 1
				if (v != 0) {
					this.type = this.tabList[v].name
					this.getTypeGoods()
				} else {
					this.getAllGoods()
				}
			},
			init() {


			},

			getAllGoods() {
				toastload()
				getPointGoods({
					page: this.page,
				}).then(res => {
					closeload()
					console.log("商品", res);

					this.loadStatus = 'loadmore';

					this.goodList = res.list
					this.addRandomData()
					if (res.last_page > res.page) {
						this.page++
					} else {
						this.loadStatus = "nomore"
					}
				})
			},

			// 上拉添加数据
			addRandomData() {
				for (let i = 0; i < this.goodList.length; i++) {
					let item = JSON.parse(JSON.stringify(this.goodList[i]))
					this.flowList.push(item);
				}
			},
			goDetail(id) {
				let obj = {
					goods_id: id
				}
				tiao('/page/pointGoodsDetail/pointGoodsDetail', obj)
			}
		}
	}
</script>
<style lang="scss" scoped>
	.box {
		min-width: 750rpx;
		min-height: 100vh;
		background-color: #f5f5f5;
		font-family: Source Han Sans CN;
		font-weight: 400;
	}

	.container {
		width: 750rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		box-sizing: border-box;
		padding: 20rpx;
		background-color: #fff;
	}

	.wrap {
		width: 750rpx;
		height: calc(100vh - 200rpx);
		overflow: auto;
	}

	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-tag-parse {
		border: 1px solid $u-type-success;
		color: #333;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}

	/* #ifdef MP-WEIXIN */
	scroll-view ::v-deep ::-webkit-scrollbar {
		width: 0;
		height: 0;
		color: transparent
	}

	/* #endif */
</style>